﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using vJine.Core.IO.Bin;
using vJine.Lua.GUI.BML;

namespace vJine.Lua.GUI.UI {
    /// <summary>
    /// WinCaseManager.xaml 的交互逻辑
    /// </summary>
    public partial class WinCaseManager : Window {
        public WinCaseManager() {
            InitializeComponent();

            this.catalogs = TestCatalog.load_cases();
            this.tbcCases.ItemsSource = this.catalogs;
        }

        public WinCaseManager(string subtitle) : this()
        {
            this.Title = string.Format("{0}-{1}", this.Title, subtitle);
        }

        List<TestCatalog> catalogs = null;

        public TestCase currentCase { get; private set; }

        private void btnContinue_Click(object sender, RoutedEventArgs e) {
            TestCatalog tc = this.tbcCases.SelectedValue as TestCatalog;
            if (tc == null) {
                MessageBox.Show(
                    "没有程序类别，无法继续", "操作错误", 
                    MessageBoxButton.OK, MessageBoxImage.Stop);
                return;
            }

            if (tc.current == null) {
                MessageBox.Show(
                    "没有选择程序，无法继续", "操作错误",
                    MessageBoxButton.OK, MessageBoxImage.Stop);
                return;
            }

            if (MessageBox.Show(
                string.Format("您选择的程序是【{0}:{1}】，确定继续吗", tc.name, tc.current.name), "操作提示",
                MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK) {
                    return;
            }

            this.currentCase = tc.current;

            this.Close();
        }

        private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
            this.btnContinue_Click(sender, e);
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e) {
            this.Close();
        }        
    }
}
